package net.bwie.realtime.jtp.Rpfunction;

import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.flink.streaming.api.functions.windowing.WindowFunction;
import org.apache.flink.streaming.api.windowing.windows.TimeWindow;
import org.apache.flink.util.Collector;

/**
 * 简介说明:
 *
 * @author: LiLi
 * @date: 2025/05/28 10:46:08
 * @version: 1.0
 */
public class ProvincePaymentAggregation implements WindowFunction<Double, String, String, TimeWindow> {

    private FastDateFormat format = FastDateFormat.getInstance("yyyy-MM-dd HH:mm:ss");

    @Override
    public void apply(String string, TimeWindow window, Iterable<Double> input, Collector<String> out) throws Exception {

        Double province_count = input.iterator().next();


        String windowStartTime = format.format(window.getStart());
        String windowEndTime = format.format(window.getEnd());
        //格式化输出
        String output = windowStartTime + "," + windowEndTime + "," + string + "," + province_count + "," + System.currentTimeMillis();

        out.collect(output);
    }
}
